cmake_minimum_required(VERSION 3.10)
project(ji)

set(CMAKE_CXX_STANDARD 11)
set(EV_SDK_PATH "/usr/local/ev_sdk")
set(CMAKE_INSTALL_PREFIX ${EV_SDK_PATH})     #设置默认安装路径

option(BUILD_EV_SDK_TESTS "whether to build ev_sdk test" ON) #控制是否编译 test-ji-api
option(WITH_TENSORRT_RUNTIME "whether to build with tesnorrt" OFF)
option(WITH_ASCENDCL_RUNTIME "whether to build with ascendcl/atlas" OFF)
option(WITH_LYNXI_RUNTIME "whether to build with lynxi sdk" OFF)
option(WITH_SOPHON_RUNTIME "whether to build with sophon/bmnn" OFF)

if(WITH_TENSORRT_RUNTIME)
    add_definitions("-DWITH_TENSORRT_RUNTIME")
endif()
if(WITH_ASCENDCL_RUNTIME)
    add_definitions("-DWITH_ASCENDCL_RUNTIME")
endif()
if(WITH_LYNXI_RUNTIME)
    add_definitions("-DWITH_LYNXI_RUNTIME")
endif()
if(WITH_SOPHON_RUNTIME)
    add_definitions("-DWITH_SOPHON_RUNTIME")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
endif()
# 设置默认编译模式
if(NOT DEFINED CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "release")
endif()

#把cmake文件夹加入Module目录
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

include(opencv) #引入opencv

include(evdeploy) #引入evdeploy

# 设置CMAKE_INSTALL_RPATH，输出的target会从该目录寻找库
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${EVDEPLOY_LIB_PATH}:${EV_SDK_PATH}/lib")


#配置点线框解析相关头文件路径和源文件
set(wkt_parser_SOURCE_DIR ${CMAKE_SOURCE_DIR}/3rd/wkt_parser)
add_subdirectory(${wkt_parser_SOURCE_DIR})

# 编译libji.so
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src libji_SOURCES)
add_library (${PROJECT_NAME} SHARED ${libji_SOURCES})

# include 头文件目录
target_include_directories(${PROJECT_NAME}
PUBLIC 
    ${EVDEPLOY_INCLUDE_DIRS}
    ${OpenCV_INCLUDE_DIRS}
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${wkt_parser_SOURCE_DIR}/include
)

# 链接库
target_link_libraries(${PROJECT_NAME}
PRIVATE
    ${OpenCV_LIBS}
    glog
    wkt_parser
    ${EVDEPLOY_LIBS}
)

#安装libji.so
install(TARGETS ${PROJECT_NAME} DESTINATION lib)

if(BUILD_EV_SDK_TESTS)
    add_subdirectory(test)  #编译 test-ji-api
endif()
